'use strict';
app.controller('profitSettingCtrl',['$scope','profitSettingService','$modal', function($scope, profitSettingService, $modal){
    $scope.settings = [];
    // call server.
    $scope.query = function(){
        profitSettingService.findAll($scope).then(function(result){
            switch (result.status) {
                case 200:
                    for(var level in result.data.data.levels) {
                        var levelName = result.data.data.levels[level];
                        $scope.settings[level] = {
                            level: level,
                            name: levelName,
                            types: result.data.data.settings[level],
                        }
                    }
                    break;
                default :
                    toaster.pop('error', "初始化数据失败", "发生未知错误！请联系管理员");
                    break;
            }
        });
    }
    $scope.query();


    $scope.openEdit = function(level, type, name){
        $scope.editData = {
            level: level,
            type: type,
            name: name
        };

        var modalInstance = $modal.open({
            templateUrl: 'tpl/agent/profit_setting_edit.html',
            controller: 'profitSettingEditCtrl',
            scope:$scope,
            size: 'sm',
            resolve: {
                data:function(){
                    return $scope;
                }
            }
        });

        modalInstance.result.then(function (result) {
            console.log(result);
        }, function () {
            console.info('Modal dismissed at: ' + new Date());
        });
    }
}]);
